package nuaa.dao;

import nuaa.domain.Collection;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 对数据表userandcollection进行操作
 */
public interface IUserAndCollectionDao {

    /**
     * 根据用户的Id获取其收藏collection对象，且为逆序查询
     * @param userId
     * @return
     */
    @Select("select collection.collectionId,collection.destinations,time " +
            "from collection,(select collectionId from userandcollection where userId=#{userId}) " +
            "as ucollection where collection.collectionId=ucollection.collectionId;")
    List<Collection> findAllCollections(Integer userId);

    /**
     * 根据userId和collectionId删除记录
     * @param userId
     * @param collectionId
     */
    @Delete("delete from userandcollection where userId=#{userId} and collectionId=#{collectionId}")
    void delete(@Param("userId") Integer userId, @Param("collectionId") Integer collectionId);

}
